home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / s_to_z / tpack / txtgrid.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-09-15  |  1.3 KB  |  51 lines

  1. unit TxtGrid;
  2.  
  3. {more excellent but underdocumented code; this component lets you autosize
  4. columns as you set text into the FitCells[] property. A default spacing of
  5. 5 pixels from the end of the text to the gridline is in effect}
  6.  
  7. interface
  8.  
  9. uses
  10.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  11.   Forms, Dialogs, Grids;
  12.  
  13. type
  14.   TTextGrid = class(TStringGrid)
  15.   private
  16.     fFromRight: Byte;
  17.     fSuspendFit: Boolean;
  18.   protected
  19.     procedure SetFitCells(ACol, ARow: Integer; const Value: string);
  20.   public
  21.     constructor Create(aOwner:TComponent); override;
  22.     property FitCells[ACol,ARow:Integer]: string write SetFitCells;
  23.   published
  24.     property FromRight: Byte read fFromRight write fFromRight default 5;
  25.     property SuspendFit: Boolean read fSuspendFit write fSuspendFit;
  26.   end;
  27.  
  28. implementation
  29.  
  30. constructor TTextGrid.Create(aOwner:TComponent);
  31. begin
  32.   inherited create(aOwner);
  33.   fFromRight:=5;
  34.   DefaultColWidth:= 10;
  35.   DefaultRowHeight:= 18;
  36. end;
  37.  
  38. procedure TTextGrid.SetFitCells(ACol, ARow: Integer; const Value: string);
  39. var
  40.   i:integer;
  41. begin
  42.   if not fSuspendFit then begin
  43.     i:=Canvas.textwidth(Value)+fFromRight;
  44.     if ColWidths[aCol]<i then
  45.       ColWidths[aCol]:=i;
  46.     end;
  47.   Cells[aCol,aRow]:=Value;
  48. end;
  49.  
  50. end.
  51.